package com.vitabuybuy.tv.network

import com.library.common.net.NetUrl
import com.vitabuybuy.tv.dto.BankCardListDto
import com.vitabuybuy.tv.dto.BillListDto
import rxhttp.IAwait
import rxhttp.wrapper.param.RxHttp
import rxhttp.wrapper.param.toResponse

/**
 * 作者：SimGa
 * 日期：2020/12/3
 * 时间：17:04
 * 包名：com.vitabuybuy.tv.network
 */
object WalletRepository {

    fun getMyWallet(): IAwait<Double> {
        return RxHttp.postJson(NetUrl.api_query_my_wallet).toResponse()
    }

    fun getBillList(
        type: String,
        pageNumber: Int,
        pageSize: Int
    ): IAwait<MutableList<BillListDto>> {
        val params = HashMap<String, Any>().apply {
            this["flow"] = mapOf(Pair("type", type))
            this["pageable"] = mapOf(
                Pair("page", pageNumber),
                Pair("size", pageSize),
                Pair("desc", "id")
            )
        }
        return RxHttp.postJson(NetUrl.api_bill_list).addAll(params).toResponse()
    }

    fun withdrawRate(): IAwait<Double> {
        return RxHttp.postJson(NetUrl.api_withdraw_rates).toResponse()
    }

    fun getBankCardList(
        pageNumber: Int,
        pageSize: Int
    ): IAwait<MutableList<BankCardListDto>> {
        val json = mapOf(
            Pair(
                "pageable",
                mapOf(
                    Pair("page", pageNumber),
                    Pair("size", pageSize),
                    Pair("desc", "id")
                )
            )
        )
        return RxHttp.postJson(NetUrl.api_query_all_bank_card).addAll(json).toResponse()
    }

    fun addNewBankCard(params: Map<String, Any>): IAwait<String> {
        return RxHttp.postJson(NetUrl.api_add_new_bank_card).add("bankCard", params).toResponse()
    }

    fun getCode(phone: String, areaCode: String): IAwait<String> {
        return RxHttp.postJson(NetUrl.api_get_phone_code_2)
            .addAll(mapOf(Pair("phone", phone), Pair("area", areaCode))).toResponse()
    }

    fun checkPhoneAndCode(code: String, phone: String, areaCode: String): IAwait<String> {
        return RxHttp.postJson(NetUrl.api_check_code_phone)
            .addAll(
                mapOf(
                    Pair("phone", phone),
                    Pair("code", code),
                    Pair("area", areaCode)
                )
            ).toResponse()
    }

    fun withDraw(amount: String, bankCardId: Int): IAwait<String> {
        return RxHttp.postJson(NetUrl.api_withdraw_amount)
            .add("amount", amount).add("bankCardId", bankCardId).toResponse()
    }
}